//
//  ZMBaseController.swift
//  LoveBeen
//
//  Created by pg on 2017/8/6.
//  Copyright © 2017年 pg. All rights reserved.
//

import UIKit

//判断用户是否登录
var isLogin: Bool  = true

class ZMBaseController: UIViewController {

     var lastTabBarIndex : Int = 0
    
    
    fileprivate lazy var visitorView : ZMVisitorView = {
       
        let view = ZMVisitorView()
        
        view.changeAddrButtonClickClosure = {
            
            self.changeAddrButtonClick()
        }
        
        return view
    }()
    
    
    
    override func loadView() {
        //用户没有登录就显示访问者界面
        if isLogin == false{
            
            view = visitorView
            
            
        }else
        {
            super.loadView()
        }
        
    }
    //MARK:- 登录按钮单击事件
    func changeAddrButtonClick() -> Void {
        
        //
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
        if isLogin {
            //初始化登录之后的导航条
            self.setupNavWhenLogin()
        }else{
            //初始化没有登录的导航条
            self.setupNavWhenNotLogin()
        }
        
        
    }
    //MARK:- 初始化没有登录时候的导航条
    func setupNavWhenNotLogin(){
        let titleLabel = UILabel()
        let text = "配送至:航头工业园区"
        let attrText = NSMutableAttributedString(string: text)
        
        attrText.addAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 13)], range: NSMakeRange(0, 4))
        attrText.addAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 18)], range: NSMakeRange(4, attrText.length-4))
        
        let attchment = NSTextAttachment()
        attchment.image = UIImage(named: "allowBlack")
        attchment.bounds = CGRect(origin: CGPoint.zero, size: CGSize(width: 10, height: 10))
        attrText.append(NSAttributedString(attachment: attchment))
        
        titleLabel.attributedText = attrText
        titleLabel.sizeToFit()
        self.navigationItem.titleView = titleLabel
        
        self.navigationController?.navigationBar.barTintColor = UIColor.white       
    }
    //MARK:- 初始化登录之后的导航条
    func setupNavWhenLogin(){
        setupNavWhenNotLogin()
    }
   

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
